<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
    <div class="nav">
        <img src="img/head.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- spacer只是占位 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.htm">写博客</a>
    </div>
    <!-- 用这个元素为页面的核心 -->
    <div class="login-container">
        <!-- 登录对话框 -->
        <div class="dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <div class="row">
                <button id="login-buton">登录</button>
            </div>
        </div>

    </div>

    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
        let button = document.querySelector("#login-buton");
        let username = document.querySelector("#username");
        let password = document.querySelector("#password");
        button.onclick = function () {

            let data = {
                username: username.value,
                password: password.value
            };
            console.log(username.value);
            $.ajax({
                type: "post",
                url: "login",
                data: JSON.stringify(data),
                contentType:'application/json; charset=utf8',
                success: function (body) {
                    let flg = body.flg;
                    if (username.value == "" || password.value == "") {
                        alert("用户名或密码不能为空");
                    } else {
                        if (flg == "false") {
                            alert("当前账号/密码填写错误,请重试!");
                        } else {
                            location.assign("blog_list.html")
                        }
                    }
                }
            });
        }
    </script>
</body>

</html>